package com.topscore.uke.mvp.presenters;

import com.topscore.uke.mvp.contractors.CreateOrUpdateAddressContractor;
import com.topscore.uke.mvp.model.CreateOrUpdateAddressModel;
import com.topscore.uke.network.request.PostAddressRequest;
import com.topscore.uke.network.request.UpdateAddressRequest;

/**
 * Created by 71468 on 2017/10/19.
 */

public class CreateOrUpdateAddressPresenter implements CreateOrUpdateAddressContractor, CreateOrUpdateAddressContractor.Presenter {
    private final View mView;
    private final Listener mListener;
    private final Model model;

    public CreateOrUpdateAddressPresenter(View view) {
        this.mView = view;
        this.mListener = new Listener() {
            @Override
            public void onPostSuccess() {
                mView.onPostAddressSuccess();
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode,errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        };
        this.model = new CreateOrUpdateAddressModel(mListener);
    }

    @Override
    public void createAddress(PostAddressRequest request) {
        mView.onLoading("请稍等");
        model.postAddress(request);
    }

    @Override
    public void updateAddress(UpdateAddressRequest request) {
        mView.onLoading("请稍等");
        model.postAddress(request);
    }
}
